﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OnlineCourse.JWTAuthorizePolicy;
using OnlineCourse.Model;
using OnlineCourse.Model.Entity;

namespace OnlineCourse.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AdvertisingController : ControllerBase
    {
        private readonly PermissionRequirement _requirement;
        private readonly Services.AdvertisingService _usbll;
        public AdvertisingController(ApplicationDbContext db, PermissionRequirement requirement)
        {

            _requirement = requirement;
            _usbll = new Services.AdvertisingService(db);
        }
        /// <summary>
        /// 添加广告信息
        /// </summary>
        /// <param name="imagePath"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        [HttpPost("Add")]
        public IActionResult Add(string imagePath,string url)
        {
            bool mark = _usbll.Add(imagePath ,url);

            return Ok(mark);
        }
        /// <summary>
        /// 更新广告信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="imagePath"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        [HttpPut("Update")]
        public IActionResult Update(Guid id, string imagePath, string url)
        {
            bool mark = _usbll.Update(id,imagePath ,url);
            return Ok(mark);
        }
        /// <summary>
        /// 删除广告信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete("Delete")]
        public IActionResult Delete(Guid id)
        {
            bool mark = _usbll.Delete(id);
            return Ok(mark);
        }
        /// <summary>
        /// 按时间倒叙查询最近i条广告
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        [HttpGet ("GetList")]
        public IActionResult GetList(int i)
        {
            var mark = _usbll.GetList(i);
            return Ok(mark);
        }
    }
}